<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
#div1 {width: 100px; height: 100px; background: red; position: absolute; left: 0; top: 0;}
</style>

    <script src="https://cdn.bootcss.com/socket.io/2.0.4/socket.io.js"></script>
<script>
window.onload = function() {
	
	var oBtn = document.getElementById('btn');
	var oDiv = document.getElementById('div1');
	var socket = null;
	
	oBtn.onclick = function() {
		
		socket = io.connect('http://localhost:8888');
		  
		socket.on('hello', function(data) {
			alert(data);
			
			this.emit('hellotoo', '欢迎欢迎');
			
		});
		
		socket.on('a', function(data) {
//			alert(data);
		});
		
		socket.on('move2', function(data) {
			oDiv.style.left = data.left + 'px';
			oDiv.style.top = data.top + 'px';
		});
		
		socket.on('receive',function(data){
			   

//               var data=JSON.parse(data)
                 console.log(data)
		})
		
	}
}
</script>
</head>

<body>
	<h1>HELLO,欢迎光临</h1>
    <input type="button" value="发送socket请求" id="btn" />
    <div id="div1">111</div>
    
    <div class="" id="dv">
    	<ul id="list"></ul>
    </div>
</body>
</html>
